<template>
  <div>
    <div class="header">
      <div class="left">
        <el-row>
          <el-button
            type="success"
            class="el-icon-circle-plus-outline"
            @click="add()"
            >新增</el-button
          >
          <el-button
            type="success"
            class="el-icon-circle-close"
            @click="Myexport"
            >导出</el-button
          >
          <el-button type="warning">全部</el-button>
          <el-button type="info">新开单</el-button>
          <el-button type="info">进行中</el-button>
          <el-button type="info">已完成</el-button>
          <el-button type="info">已暂停</el-button>
        </el-row>
      </div>
      <div class="right">
        <el-input v-model="input" placeholder="查找" class="myinput"></el-input>
        <el-button class="el-icon-search sou" @click="select"></el-button>
      </div>
    </div>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="typesCustomer.title" label="类型">
      </el-table-column>
      <el-table-column prop="number" label="门诊编号"> </el-table-column>
      <el-table-column prop="title" label="标题"> </el-table-column>
      <el-table-column prop="customer.username" label="患者"> </el-table-column>
      <el-table-column prop="consultation" label="会科诊室"> </el-table-column>
      <el-table-column prop="hospitalized" label="住院床号"> </el-table-column>
      <el-table-column prop="customer.employee.realName" label="负责人">
      </el-table-column>
      <el-table-column prop="registerMoney" label="金额"> </el-table-column>
      <el-table-column prop="createTime" label="时间" width="140">
        <template slot-scope="scope">{{
          scope.row.createTime | dateFormat
        }}</template></el-table-column
      >
      <el-table-column prop="customerDrugList.length" label="药品">
      </el-table-column>
      <el-table-column prop="paymentMoney" label="付款">
        <template slot-scope="scope">
          <span v-if="scope.row.paymentMoney == 1">已付款</span>
          <span v-if="scope.row.paymentMoney == 2">未付款</span>
        </template>
      </el-table-column>
      <el-table-column prop="statusCustomer.title" label="状态">
      </el-table-column>
      <el-table-column prop="address" label="操作" class="roeone" width="300">
        <template slot-scope="scope">
          <el-button
            type="primary"
            class="el-icon-edit modbt"
            @click="mod(scope.row)"
            >修改</el-button
          >
          <el-button
            type="primary"
            class="el-icon-search modbt"
            @click="dialogTableVisible = true"
            >查看</el-button
          ><el-button
            type="danger"
            class="el-icon-close modbt"
            @click="del(scope.row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <page :countNum="countNum" @changePage="changePage"></page>

    <!-- 查看弹窗 -->
    <el-dialog title="诊断报告单" :visible.sync="dialogTableVisible">
      <table class="see">
        <tr>
          <td>患者姓名：</td>
          <td></td>
          <td colspan="2">患者性别：</td>
        </tr>
        <tr>
          <td>患者年龄：</td>
          <td></td>
          <td colspan="2">开单日期：</td>
        </tr>
        <tr>
          <td>门诊编号：</td>
          <td></td>
          <td colspan="2">诊断标题：</td>
        </tr>
        <tr>
          <td>会诊科室：</td>
          <td></td>
          <td colspan="2">住院床号：</td>
        </tr>
        <tr>
          <td>诊断信息：</td>
          <td colspan="6"></td>
        </tr>
        <tr>
          <td>图片</td>
          <td>药品名称</td>
          <td>药品编号</td>
          <td>备注</td>
          <td>单价</td>
          <td>数量</td>
          <td>金额</td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
        </tr>
        <tr>
          <td colspan="6">总计：</td>
          <td></td>
        </tr>
        <tr>
          <td colspan="2">医生签字</td>
          <td colspan="5">患者签字</td>
        </tr>
        <tr>
          <td colspan="2"></td>
          <td colspan="5"></td>
        </tr>
      </table>
      <button>打印报告</button>
    </el-dialog>
  </div>
</template>
<script>
import { home, Myexport, del } from "../../utils/api/diagnostic";
import page from "../../components/report_ssh/pageFtoor.vue";
export default {
  name: "diagnPage",
  created() {
    this.home();
  },
  methods: {
    //查询
    select() {
      this.all.search = this.input;
      this.home();
      // console.log(this.all.search);
    },
    //页码
    changePage(page) {
      this.all.page = page;
      this.home();
    },
    //修改
    mod(row) {
      // console.log(row);
      this.$router.push({
        path: "/home/Diagnostic/Diagnostic_mod",
        query: { ...row },
      });
    },
    //增加
    add() {
      this.$router.push("/home/Diagnostic/Diagnostic_add");
    },
    //初始化
    home() {
      home(this.all).then((data) => {
        this.tableData = data.data.data.customerDiagnosis;
        console.log(data);
        this.countNum = data.data.data.count;
      });
    },
    //删除
    del(id) {
      del(id).then((data) => {
        this.home();
      });
      this.$message({
        message: "您已成功删除",
        type: "success",
      });
    },
    Myexport() {
      Myexport().then((data) => {
        this.download(data.data);
        // console.log(data);
      });
    },
    // 将后台返回的乱码解析成文件下载
    download(data) {
      if (!data) {
        return;
      }
      let url = window.URL.createObjectURL(new Blob([data]));
      let link = document.createElement("a");
      link.style.display = "none";
      link.href = url;
      link.setAttribute("download", "诊断信息报表.xlsx");

      document.body.appendChild(link);
      link.click();
    },
  },
  components: { page },
  data() {
    return {
      input: "",
      dialogTableVisible: false,
      tableData: [],
      all: {
        search: "",
        limit: 20,
        page: 1,
        status: "",
      },
      countNum: 0,
    };
  },
};
</script>
<style lang="less" scoped>
.top {
  padding: 10px;
  font-size: 18px;
  box-sizing: border-box;
}
.header {
  button {
    line-height: 5px;
    font-weight: bold;
    margin: 10px 6px;
  }
}
.left {
  float: left;
}
.right {
  float: right;
  button {
    height: 40px;
    margin: 0;
  }
  .myinput {
    width: 200px;
    height: 30px;
  }
}
.modbt {
  width: 70px;
  // height: 26px;
  line-height: 10px;
  font-weight: bold;
}
.block {
  text-align: center;
  margin-top: 10px;
}
.see {
  border: 1px solid black;
  border-collapse: collapse;
  tr {
    border: 1px solid black;
    td {
      border: 1px solid black;
    }
  }
}
</style>
